package com.example.jksj.bookmanagement.pro.mine.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;

import com.example.jksj.bookmanagement.R;
import com.example.jksj.bookmanagement.common.MyActivity;
import com.example.jksj.bookmanagement.utils.ShareUtils;

import ch.ielse.view.SwitchView;

public class SettingActivity extends MyActivity implements View.OnClickListener {

    private SwitchView MessageSendSwitch;   //消息推送开关
    private SwitchView StatusSendSwitch;    //状态栏推送开关
    private SwitchView AutoUpdateSwitch;    //自动更新开关
    private Button UserManageBtn;           //用户管理按钮
    private Button UpdatePswBtn;            //修改密码按钮
    private Button RANBtn;                  //实名认证按钮
    private Button CleanCacheBtn;           //清理缓存按钮
    private Button UpdateBtn;               //软件更新按钮

    private boolean isOpenMessageSend = true;   //是否开启消息推送
    private boolean isOpenStatusSend = true;    //是否开启状态栏推送
    private boolean isOpenAutoUpdate = true;    //是否开启自动更新

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected int getTitleBarId() {
        return R.id.tb_title_setting;
    }

    @Override
    protected void initView() {
        MessageSendSwitch = findViewById(R.id.sv_openMessageSend_setting);
        MessageSendSwitch.setOnClickListener(this);

        StatusSendSwitch = findViewById(R.id.sv_openStatuBarSend_setting);
        StatusSendSwitch.setOnClickListener(this);

        AutoUpdateSwitch = findViewById(R.id.sv_openAutoUpdate_setting);
        AutoUpdateSwitch.setOnClickListener(this);

        UserManageBtn = findViewById(R.id.btn_userManger_setting);
        UserManageBtn.setOnClickListener(this);

        UpdatePswBtn = findViewById(R.id.btn_updatePsw_setting);
        UpdatePswBtn.setOnClickListener(this);

        RANBtn = findViewById(R.id.btn_RNA_setting);
        RANBtn.setOnClickListener(this);

        CleanCacheBtn = findViewById(R.id.btn_cleanCache_setting);
        CleanCacheBtn.setOnClickListener(this);

        UpdateBtn = findViewById(R.id.btn_update_setting);
        UpdateBtn.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        //默认全都开启
        isOpenMessageSend = ShareUtils.getBoolean("isOpenMessageSend", true);
        //L.i("isOpenMessageSend:" + isOpenMessageSend);
        MessageSendSwitch.setOpened(isOpenMessageSend);

        isOpenStatusSend = ShareUtils.getBoolean("isOpenStatusSend", true);
        //L.i("isOpenStatusSend:" + isOpenStatusSend);
        StatusSendSwitch.setOpened(isOpenStatusSend);

        isOpenAutoUpdate = ShareUtils.getBoolean("isOpenAutoUpdate", true);
        //L.i("isOpenAutoUpdate:" + isOpenAutoUpdate);
        AutoUpdateSwitch.setOpened(isOpenAutoUpdate);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.sv_openMessageSend_setting:
                isOpenMessageSend = MessageSendSwitch.isOpened();
                break;

            case R.id.sv_openStatuBarSend_setting:
                isOpenStatusSend = StatusSendSwitch.isOpened();
                break;

            case R.id.sv_openAutoUpdate_setting:
                isOpenAutoUpdate = AutoUpdateSwitch.isOpened();
                break;

            case R.id.btn_userManger_setting:
                startActivity(new Intent(SettingActivity.this, UserManageActivity.class));
                break;

            case R.id.btn_updatePsw_setting:
                break;

            case R.id.btn_RNA_setting:
                startActivity(AuthenticationActivity.class);
                break;

            case R.id.btn_cleanCache_setting:
                break;

            case R.id.btn_update_setting:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //存入配置信息
        ShareUtils.putBoolean("isOpenMessageSend", isOpenMessageSend);
        ShareUtils.putBoolean("isOpenStatusSend", isOpenStatusSend);
        ShareUtils.putBoolean("isOpenAutoUpdate", isOpenAutoUpdate);
    }
}
